<template>
    <div style="overflow-x:hidden">
      <div>
        <div class="tree-centent">现象:{{txts}}</div>
        <div class="tree-centent green">原因:<span v-for="(item,index) in answertree" :key="index">{{item}}</span></div>
      </div>
      <div style="height: 350px;overflow-y: scroll;margin-right: -10px">
        <el-tree v-loading="loading" element-loading-text="拼命加载中"
          :data="treeData"
          show-checkbox
          node-key="name"
          default-expand-all
          ref="tree"
          highlight-current
          @check-change="changes"
          check-strictly="true"
          :props="defaultProps">
        </el-tree>
      </div>
    </div>
</template>

<script>
    export default {
        name: "treePage",
      props:{
        answertree:null,
        txts:null
      },
      data(){
          return{
            defaultProps: {
              children: 'children',
              label: 'name'
            },
            ids:[],
            treeData:[],
            loading:true
          }
      },
      mounted(){
        let that = this;
        let arr = that.answertree
        // that.ids = that.answertree
        that.$post('vpo/md/answer', {})
          .then((response) => {
            console.log(response);
            that.treeData=response.data;
            this.loading = false;
          }).catch(err => {
          that.$message.error(err);
        })
        that.$refs.tree.setCheckedKeys(arr);
      },
      methods: {
        changes(e){
          let that = this;
          let arr = []
          // arr = that.ids
          // console.log(e.name)
          // that.ids.push(e.name)
          // console.log(that.ids);
          // for(let i = 0;i < that.answertree.length;i++){
          //   that.ids.push(that.answertree[i])
          // }
          that.$emit('treeFn',that.$refs.tree.getCheckedKeys())
        },
      },
    }
</script>

<style scoped>
  .tree-centent{
    text-align: left;
    margin: 10px 0;
  }
  .green{
    color: green;
    overflow: hidden;/*超出部分隐藏*/
    text-overflow:ellipsis;/* 超出部分显示省略号 */
    white-space: nowrap;/*规定段落中的文本不进行换行 */
  }
</style>
